package com.hospital.hospitalsystem.modules.medicine.biz;

import com.github.pagehelper.PageHelper;
import com.hospital.hospitalsystem.base.PageData;
import com.hospital.hospitalsystem.modules.hospital.dto.DepartmentRsp;
import com.hospital.hospitalsystem.modules.medicine.dao.entity.HospitalMedicalHistoryEntity;
import com.hospital.hospitalsystem.modules.medicine.dto.HospitalMedicalHistoryListReq;
import com.hospital.hospitalsystem.modules.medicine.dto.HospitalMedicalHistoryReq;
import com.hospital.hospitalsystem.modules.medicine.dto.HospitalMedicalHistoryRsp;
import com.hospital.hospitalsystem.modules.medicine.dto.HospitalMedicalRsp;
import com.hospital.hospitalsystem.modules.medicine.service.HospitalMedicalHistoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/4/4
 */
@Service
public class HospitalMedicalHistoryBiz {

    @Autowired
    private HospitalMedicalHistoryService hospitalMedicalHistoryService;

    /**
     * 添加信息描述
     * @param req
     */
    public void addMsg(HospitalMedicalHistoryReq req) {
        HospitalMedicalHistoryEntity hospitalMedicalHistoryEntity = new HospitalMedicalHistoryEntity();
        BeanUtils.copyProperties(req,hospitalMedicalHistoryEntity);
        hospitalMedicalHistoryService.insertSelective(hospitalMedicalHistoryEntity);
    }

    /**
     * 查找历史记录
     * @param req
     * @return
     */
    public PageData<HospitalMedicalHistoryRsp> getMedicalHistory(HospitalMedicalHistoryListReq req) {
        com.github.pagehelper.Page<DepartmentRsp> page = PageHelper.startPage(
                req.getCurrentPage(), req.getPageSize()
        );
        List<HospitalMedicalHistoryRsp> result = hospitalMedicalHistoryService.getMedicalHistory(req);
        int longs = ((Number) page.getTotal()).intValue();
        PageData<HospitalMedicalHistoryRsp> pageData = PageData.of(result,page.getPageNum(),page.getPageSize(),longs);
        return pageData;
    }
}
